<!DOCTYPE html>
<html lang="en">
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="{devRootAppend}/resources/css/bootstrap.min.css">
        <link rel="stylesheet" href="{devRootAppend}/resources/fontawesome/css/all.min.css">
        <link rel="stylesheet" href="{devRootAppend}/resources/css/dev-console.css?2">
        <link rel="stylesheet" href="{devRootAppend}/resources/css/logstream.css">
        <link rel="stylesheet" href="{devRootAppend}/resources/css/tests.css">
        {#insert styleref /}
        
        <link rel="shortcut icon" type="image/png" href="{devRootAppend}/resources/images/favicon.ico" >

        <style>
            {#insert style /}
        </style>

        <title>
            {#if currentExtensionName?? && currentExtensionName != 'Eclipse Vert.x - HTTP'}
            {currentExtensionName} ›
            {/if}
            {#insert title/}
            {#if applicationName and applicationVersion} | {applicationName} {applicationVersion}{/if}
        </title>
    </head>
    <body>
        <!-- Top Header -->
        <nav id="stickyTopHeaderNavBar" class="navbar sticky-top navbar-dark bg-dark">
            <a class="navbar-brand" href="{devRootAppend}/">
                <img src="{devRootAppend}/resources/images/quarkus_icon_rgb_reverse.svg" width="40" height="30" class="d-inline-block align-middle" alt="Quarkus"/>
                <span id="navbar-title" class="align-middle">Dev UI</span>
            </a>
            {#if currentExtensionName??}
            <span id="navbar-subtitle" class="navbar-nav">
                <span class="navbar-item">
                    {#if currentExtensionName == 'Eclipse Vert.x - HTTP'}
                    <i class="fas fa-chevron-right fa-sm breadcrumb-separator"></i> {#insert title/}
                    {#else}
                    <i class="fas fa-chevron-right fa-sm breadcrumb-separator"></i> {currentExtensionName}{#insert breadcrumbs/}<i class="fas fa-chevron-right fa-sm breadcrumb-separator"></i> {#insert title/}
                    {/if}
                </span>
            </span>   
            {/}  
            <span class="navbar-text">
                {#if applicationName and applicationVersion}{applicationName} {applicationVersion} (powered by Quarkus {quarkusVersion}){/if}
            </span>
        </nav>

        <!-- Content section / Tiles -->
        <div class="container{#if fluid??}-fluid{/if} main-container">

            {#if flash.message??}
            <div class="alert alert-{flash.message.class} show fade" role="alert" data-timer="{flash.displayTime}">
                {flash.message.text}
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            {/if}
            <div class="position-fixed top-0 right-0 p-3" style="z-index: 5; right: 0; top 0;">
                <div class="toast hide" role="alert" aria-live="assertive" aria-atomic="true" data-delay="5000">
                  <div class="toast-header">
                    <i class="fas fa-info-circle"></i> 
                    <strong id="toastHeader" class="mr-auto"></strong>
                    <button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>
                  <div id="toastMessage" class="toast-body">
                  </div>
                </div>
            </div>
            
            {#insert body/}
        </div>

        <!-- Footer -->
        <div id="devUiFooter" class="footer fixed-bottom">

            <div id="devUiFooterToolbar" class="container-fluid bg-dark position-sticky">
                <div class="row">
                    <div class="col-sm">
                        <div class="row">
                            <div class="col-md-auto pr-0">
                                <a id="devUiFooterOpenButton" class="btn devUiFooterButton hideOnOpenFooter">
                                    <i class="fas fa-caret-up fa-lg"></i> Open
                                </a>
                                <a id="devUiFooterCloseButton" class="btn devUiFooterButton showOnOpenFooter">
                                    <i class="fas fa-caret-down fa-lg"></i> Close
                                </a>
                            </div>
                            <div class="col-md-auto px-0">
                                {#include logmanagerNav /}
                            </div>
                            <div class="col">
                                <a id="devUiFooterResizeButton" class="btn devUiFooterButton float-right showOnOpenFooter">
                                    <i class="fas fa-arrows-alt-v"></i>
                                </a>
                            </div>
                        </div>
                    </div>
                    <div id="testsInFooter" class="col-sm">
                        {#include testsNav}{/include}
                    </div>
                </div>
            </div>
            
            <div id="devUiFooterContent">
                {#include logmanagerLog}{/include}
            </div>
        </div>
        
        {#include logmanagerModals /}
        {#include testsModals /}

        <script src="{devRootAppend}/resources/js/jquery.min.js"></script>
        <script src="{devRootAppend}/resources/js/bootstrap.bundle.min.js"></script>
        <script src="{devRootAppend}/resources/js/dev-console.js"></script>
        <script src="{devRootAppend}/resources/js/logstream.js"></script>
        <script src="{devRootAppend}/resources/js/tests.js"></script>
        {#insert scriptref /}
        
        <script>
                            {|
                                    if (jQuery(".alert").length) {
                            // dismiss alert
                            jQuery(function() {
                            window.setTimeout(function(){
                            jQuery(".alert").alert("close");
                            }, jQuery(".alert").data("timer"));
                            });
                            }
                            |}
                            var sourceMap = \{\};
                            {#for sourcePackageEntry in ideInfo:sourcePackages}
                            var {sourcePackageEntry.key}Packages = [];
                            {#for rootPackage in sourcePackageEntry.value}
                            {sourcePackageEntry.key}Packages.push("{rootPackage}")
                            {/for}
                                    sourceMap["{sourcePackageEntry.key}"] = {sourcePackageEntry.key}Packages;
                            {/for}
                            var sourceLocationMap = \{\};
                            {#for sourcePackageEntry in ideInfo:locationPackages}
                            sourceLocationMap["{sourcePackageEntry.key}"] = [];
                            {#for rootPackage in sourcePackageEntry.value}
                            sourceLocationMap["{sourcePackageEntry.key}"].push("{rootPackage}")
                            {/for}
                            {/for}
                            var ideLinkType = "{ideInfo:ideLinkType}";
                            var ideClientLinkFormat = "{ideInfo:ideClientLinkFormat}";
                            var ideServerLinkEndpoint = "{ideInfo:ideServerLinkEndpoint}";
                            var devRootAppend = "{devRootAppend}";
                            {|
                                    var langToExt = {"java": "java", "kotlin": "kt"};
                            function ideKnown() {
                            return (ideLinkType == "client") || (ideLinkType == "server");
                            }

                            // if the class is an application class, return the source language it was written in
                            // or null if the class is not an application class
                            function appClassLang(className) {
                            for (var key in sourceMap){
                            if (sourceMap.hasOwnProperty(key)) {
                            var packages = sourceMap[key];
                            for (var i = 0; i < packages.length; i++) {
                            if (className.startsWith(packages[i] + ".") || ((packages[i] === "") && (className.indexOf('.') == -1))) {
                            return key;
                            }
                            }
                            }
                            }
                            return null;
                            }

                            // if the class is an application class, return the source language it was written in
                            // or null if the class is not an application class
                            function appClassLocation(className) {
                            for (var key in sourceLocationMap){
                            if (sourceLocationMap.hasOwnProperty(key)) {
                            var packages = sourceLocationMap[key];
                            for (var i = 0; i < packages.length; i++) {
                            if (className.startsWith(packages[i] + ".") || ((packages[i] === "") && (className.indexOf('.') == -1))) {
                            return key;
                            }
                            }
                            }
                            }
                            return null;
                            }

                            function openInIDE(className, line) {
                            var location = appClassLocation(className);
                            if (location == null) {
                            console.error("Unable to determine file name of class: '" + className + "'");
                            return;
                            }
                            var lang = appClassLang(className);
                            if (lang == null) {
                            console.error("Unable to determine file name of class: '" + className + "'");
                            return;
                            }
                            var effectiveClassName = className;
                            var dollarIndex = className.indexOf("$");
                            if (dollarIndex > -1) {
                            effectiveClassName = className.substring(0, dollarIndex);
                            }
                            var fileName = effectiveClassName.replaceAll(".", "/") + "." + langToExt[lang];
                            if (ideLinkType == "client") {
                            var location = ideClientLinkFormat.replace("{0}", location + "/" + fileName);
                            if (line) {
                            location = location.replace("{1}", line);
                            } else {
                            location = location.replace(":{1}", "");
                            }
                            window.location = location;
                            return;
                            } else if (ideLinkType == "server") {

                            var fd = new FormData();
                            fd.append('className', className);
                            fd.append('lang', lang);
                            if (line) {
                            fd.append('line', line);
                            }

                            $.ajax({
                            url: window.location.protocol + "//" + window.location.host + devRootAppend + ideServerLinkEndpoint,
                                    data: fd,
                                    processData: false,
                                    contentType: false,
                                    type: 'POST'
                            }).fail(function() {
                            console.error("Unable to open class: '" + className + "' in the IDE. See server logs for more information");
                            });
                            } else {
                            console.error("Unknown IDE link type: " + ideLinkType);
                            }
                            }
                            
                            function showToastMessage(header, message){
                                $('#toastHeader').text("" + header);
                                $('#toastMessage').text(message);
                                
                                $('.toast').toast({
                                    autohide: true,
                                    delay: 5000
                                }).toast('show');
                            }
                            
                            |}

                            {#insert script / }
        </script>
    </body>
</html>
